home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / code_gen / codewiz / codewiz.as_ / codewiz.as
Encoding:
INI File  |  1995-03-28  |  35.9 KB  |  1,218 lines

  1. [1]
  2. GetSysDir returns the path of the Windows System directory.  Pass it the name of the string you want SysPath assigned to.
  3.  
  4. [Code]
  5. 'Declares for GetSystemDir
  6. Declare Function GetSystemDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  7.  
  8. Sub GetSystemDir (SystemPath$)
  9. DIM Sys As String * 256   
  10. x = GetSystemDirectory(Sys, Len(Sys))
  11. x = InStr(1, Sys, Chr$(0))
  12. SystemPath$ = Left$(Sys, Instr(Sys,Chr$(0))-1)
  13. End Sub
  14.  
  15. [Stop]
  16. [2]
  17. Loaded tells if an app of the passed classname is loaded
  18. [Code]
  19. 'Declares for Loaded
  20. Declare Function FindWindow Lib "user" (ByVal CName As Any, ByVal Caption As Any)
  21.  
  22. Function Loaded (ClassName$)
  23. Loaded = FindWindow(ClassName$, 0&)
  24. End Function
  25. [Stop]
  26. [3]
  27. RestoreApp restores the windows whose handle you pass to it.
  28. [Code]
  29. 'Declares for RestoreApp
  30. Declare Function IsIconic Lib "user" (ByVal hWnd As Any)
  31.  
  32. Sub RestoreApp (wHandle)
  33. WM_SYSCOMMAND = &H112
  34. SC_RESTORE = &HF120
  35.  
  36. If IsIconic(Instance) Then
  37. T = PostMessage(Instance, WM_SYSCOMMAND, SC_RESTORE, 0)
  38. WaitSecs 1
  39. End If
  40. End Sub
  41. [Stop]
  42. [4]
  43. Tracks a popup menu.  
  44. Pass it the number (going from right to left) of the menu you wish to view, the X & Y coordinates at which it should pop up (as returned by a mousedown event), the form on which the mousedown event took place (and over which the menu should appear), and the form to which the menu belongs (which may or may not be the same as the previous form).
  45.  
  46. [Code]
  47. 'TrackPopupMenu declares
  48. Declare Function TrackPopupMenu% Lib "user" (ByVal hMenu%, ByVal wFlags%, ByVal X%, ByVal Y%, ByVal r2%, ByVal hWnd%, ByVal r1&)
  49. Declare Function GetMenu% Lib "user" (ByVal hWnd%)
  50. Declare Function GetSubMenu% Lib "user" (ByVal hMenu%, ByVal nPos%)
  51.  
  52.  
  53. Sub TrackPopUp (Menu As Integer, X As Single, Y As Single, F as Form, MenuForm As Form)
  54.           Const PIXEL = 3
  55.           Const TWIP = 1
  56.           F.ScaleMode = PIXEL
  57.           InPixels = F.ScaleWidth
  58.           F.ScaleMode = TWIP
  59.           ix = (X + F.Left) \ (F.ScaleWidth \ InPixels)
  60.           iy = (Y + (F.Top + (F.Height - F.ScaleHeight - (F.Width - F.ScaleWidth)))) \ (F.ScaleWidth \ InPixels)
  61.           hMenu% = GetMenu(MenuForm.hWnd)
  62.           hSubMenu% = GetSubMenu(hMenu%, Menu)
  63.           '2 tells it to use right mouse button, 1 the left button
  64.           r = TrackPopupMenu(hSubMenu%, 2, ix, iy, 0, MenuForm.hWnd, 0)
  65. End Sub
  66.  
  67. [Stop]
  68. [5]
  69. Extracts icons from a specified Exe file. 
  70.  
  71.  
  72. [Code]
  73. 'Declares for IconExtractor
  74. Const GWW_HINSTANCE = (-6)
  75. Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
  76. Declare Function ExtractIcon Lib "shell" (ByVal lpHandle As Integer, ByVal lpExe As String, ByVal lpiconindex As Integer) As Integer
  77. Declare Function DrawIcon Lib "USER" (ByVal lpHandle As Integer, ByVal xcoord As Integer, ByVal ycoord As Integer, ByVal Hicon As Integer) As Integer
  78.  
  79. Sub IconExtractor (ExeFile$, F as Form, Pic as Picture)
  80. Handle = F.hWnd
  81. z = SCREEN.HEIGHT
  82.     Select Case z
  83.         Case 7000
  84.             X = 2: Y = 1
  85.         Case 7200
  86.             X = 3: Y = 0
  87.         Case 9000
  88.             X = 3: Y = 0
  89.         Case Is > 9000
  90.             X = 8: Y = 4
  91.     End Select
  92.                 
  93.     Static Looper
  94.     Looper = Looper + 1
  95.     Inst = GetWindowWord(Handle, GWW_HINSTANCE)
  96.     Hicon = ExtractIcon(Inst, ExeFile$, Looper - 1)
  97.     If Hicon = 0 Then
  98.         If Looper > 0 Then
  99.             Hicon = ExtractIcon(Inst, ExeFile$, 0)
  100.             Looper = 1
  101.         Else Beep: Exit Sub
  102.         End If
  103.     End If
  104.     F.Pic.CLS
  105.     Draw = DrawIcon(F.Pic.hDC, X, Y, Hicon)
  106. End Sub
  107.  
  108. [Stop]
  109. [6]
  110. Testlength can be used to test whether more than a specified number of characters has been entered into a textbox. If so, it deletes backwards from the insertion point until the text length is within the specified limit.
  111. [Code]
  112. 'Declares for TestLength
  113. Global Const MB_ICONEXCLAMATION = 48
  114.  
  115. Sub TestLength (C As Control, L As Integer)
  116. Select Case Len(C.Text)
  117. Case Is <= L
  118. Exit Sub
  119. Case Else
  120. MsgBox "This field is limited to " + Str$(L) + " characters only! ", MB_ICONEXCLAMATION, "CopyFlow"
  121. LeftText$ = Left$(C.Text, C.SelStart)
  122. RightText$ = Mid$(C.Text, C.SelStart + 1)
  123. LeftText$ = Left$(LeftText$, L - Len(RightText$))
  124. C.Text = LeftText$ + RightText$
  125. End Select
  126. End Sub
  127.  
  128. [Stop]
  129. [7]
  130. The Exists%() function returns a value of TRUE if the specified file exists, or FALSE if it doesn't.
  131. [Code]
  132. Function Exists% (F$)
  133. On Error Resume Next
  134. X& = FileLen(F$)
  135. If X& Then Exists% = True
  136. End Function
  137.  
  138. [Stop]
  139. [8]
  140. Function determines if passed pathname is valid
  141. [Code]
  142. '------------------------------------------------------
  143. ' Function:   IsValidPath as integer
  144. ' arguments:  DestPath$         a string that is a full path
  145. '             DefaultDrive$     the default drive.  eg.  "C:"
  146. '
  147. '  If DestPath$ does not include a drive specification,
  148. '  IsValidPath uses Default Drive
  149. '
  150. '  When IsValidPath is finished, DestPath$ is reformated
  151. '  to the format "X:\dir\dir\dir\"
  152. '
  153. ' Result:  True (-1) if path is valid.
  154. '          False (0) if path is invalid
  155. '-------------------------------------------------------
  156. Function IsValidPath (DestPath$, ByVal DefaultDrive$) As Integer
  157.  
  158.     '----------------------------
  159.     ' Remove left and right spaces
  160.     '----------------------------
  161.     DestPath$ = RTrim$(LTrim$(DestPath$))
  162.     
  163.  
  164.     '-----------------------------
  165.     ' Check Default Drive Parameter
  166.     '-----------------------------
  167.     If Right$(DefaultDrive$, 1) <> ":" Or Len(DefaultDrive$) <> 2 Then
  168.         MsgBox "Bad default drive parameter specified in IsValidPath Function.  You passed,  """ + DefaultDrive$ + """.  Must be one drive letter and "":"".  For example, ""C:"", ""D:""...", 64, "Setup Kit Error"
  169.         GoTo parseErr
  170.     End If
  171.     
  172.  
  173.     '-------------------------------------------------------
  174.     ' Insert default drive if path begins with root backslash
  175.     '-------------------------------------------------------
  176.     If Left$(DestPath$, 1) = "\" Then
  177.         DestPath$ = DefaultDrive + DestPath$
  178.     End If
  179.     
  180.     '-----------------------------
  181.     ' check for invalid characters
  182.     '-----------------------------
  183.     On Error Resume Next
  184.     tmp$ = Dir$(DestPath$)
  185.     If Err <> 0 Then
  186.         GoTo parseErr
  187.     End If
  188.     
  189.  
  190.     '-----------------------------------------
  191.     ' Check for wildcard characters and spaces
  192.     '-----------------------------------------
  193.     If (InStr(DestPath$, "*") <> 0) GoTo parseErr
  194.     If (InStr(DestPath$, "?") <> 0) GoTo parseErr
  195.     If (InStr(DestPath$, " ") <> 0) GoTo parseErr
  196.          
  197.     
  198.     '------------------------------------------
  199.     ' Make Sure colon is in second char position
  200.     '------------------------------------------
  201.     If Mid$(DestPath$, 2, 1) <> Chr$(58) Then GoTo parseErr
  202.     
  203.  
  204.     '-------------------------------
  205.     ' Insert root backslash if needed
  206.     '-------------------------------
  207.     If Len(DestPath$) > 2 Then
  208.       If Right$(Left$(DestPath$, 3), 1) <> "\" Then
  209.         DestPath$ = Left$(DestPath$, 2) + "\" + Right$(DestPath$, Len(DestPath$) - 2)
  210.       End If
  211.     End If
  212.  
  213.     '-------------------------
  214.     ' Check drive to install on
  215.     '-------------------------
  216.     drive$ = Left$(DestPath$, 1)
  217.     ChDrive (drive$)                                                        ' Try to change to the dest drive
  218.     If Err <> 0 Then GoTo parseErr
  219.     
  220.     '-----------
  221.     ' Add final \
  222.     '-----------
  223.     If Right$(DestPath$, 1) <> "\" Then
  224.         DestPath$ = DestPath$ + "\"
  225.     End If
  226.     
  227.  
  228.     '-------------------------------------
  229.     ' Root dir is a valid dir
  230.     '-------------------------------------
  231.     If Len(DestPath$) = 3 Then
  232.         If Right$(DestPath$, 2) = ":\" Then
  233.             GoTo ParseOK
  234.         End If
  235.     End If
  236.     
  237.  
  238.     '------------------------
  239.     ' Check for repeated Slash
  240.     '------------------------
  241.     If InStr(DestPath$, "\\") <> 0 Then GoTo parseErr
  242.         
  243.     '--------------------------------------
  244.     ' Check for illegal directory names
  245.     '--------------------------------------
  246.     legalChar$ = "!#$%&'()-0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`{}~."
  247.     BackPos = 3
  248.     forePos = InStr(4, DestPath$, "\")
  249.     Do
  250.         temp$ = Mid$(DestPath$, BackPos + 1, forePos - BackPos - 1)
  251.         
  252.         '----------------------------
  253.         ' Test for illegal characters
  254.         '----------------------------
  255.         For i = 1 To Len(temp$)
  256.             If InStr(legalChar$, UCase$(Mid$(temp$, i, 1))) = 0 Then GoTo parseErr
  257.         Next i
  258.  
  259.         '-------------------------------------------
  260.         ' Check combinations of periods and lengths
  261.         '-------------------------------------------
  262.         periodPos = InStr(temp$, ".")
  263.         length = Len(temp$)
  264.         If periodPos = 0 Then
  265.             If length > 8 Then GoTo parseErr                         ' Base too long
  266.         Else
  267.             If periodPos > 9 Then GoTo parseErr                      ' Base too long
  268.             If length > periodPos + 3 Then GoTo parseErr             ' Extension too long
  269.             If InStr(periodPos + 1, temp$, ".") <> 0 Then GoTo parseErr' Two periods not allowed
  270.         End If
  271.  
  272.         BackPos = forePos
  273.         forePos = InStr(BackPos + 1, DestPath$, "\")
  274.     Loop Until forePos = 0
  275.  
  276. ParseOK:
  277.     IsValidPath = True
  278.     Exit Function
  279.  
  280. parseErr:
  281.     IsValidPath = False
  282. End Function
  283.  
  284. [Stop]
  285. [9]
  286. Creates the passed path
  287. [Code]
  288. Function CreatePath (ByVal DestPath$) As Integer
  289. '---------------------------------------------
  290. ' Create the path contained in DestPath$
  291. ' First char must be drive letter, followed by
  292. ' a ":\" followed by the path, if any.
  293. '---------------------------------------------
  294.  
  295.     Screen.MousePointer = 11
  296.  
  297.     '---------------------------------------------
  298.     ' Add slash to end of path if not there already
  299.     '---------------------------------------------
  300.     If Right$(DestPath$, 1) <> "\" Then
  301.         DestPath$ = DestPath$ + "\"
  302.     End If
  303.           
  304.  
  305.     '-----------------------------------
  306.     ' Change to the root dir of the drive
  307.     '-----------------------------------
  308.     On Error Resume Next
  309.     ChDrive DestPath$
  310.     If Err <> 0 Then GoTo errorOut
  311.     ChDir "\"
  312.  
  313.     '-------------------------------------------------
  314.     ' Attempt to make each directory, then change to it
  315.     '-------------------------------------------------
  316.     BackPos = 3
  317.     forePos = InStr(4, DestPath$, "\")
  318.     Do While forePos <> 0
  319.         temp$ = Mid$(DestPath$, BackPos + 1, forePos - BackPos - 1)
  320.  
  321.         Err = 0
  322.         MkDir temp$
  323.         If Err <> 0 And Err <> 75 Then GoTo errorOut
  324.  
  325.         Err = 0
  326.         ChDir temp$
  327.         If Err <> 0 Then GoTo errorOut
  328.  
  329.         BackPos = forePos
  330.         forePos = InStr(BackPos + 1, DestPath$, "\")
  331.     Loop
  332.                  
  333.     CreatePath = True
  334.     Screen.MousePointer = 0
  335.     Exit Function
  336.                  
  337. errorOut:
  338.     MsgBox "Error While Attempting to Create Directories on Destination Drive.", 48, "SETUP"
  339.     CreatePath = False
  340.     Screen.MousePointer = 0
  341.  
  342. End Function
  343.  
  344. [Stop]
  345. [10]
  346. Creates a Program Manager group.
  347.  
  348. [Code]
  349. Sub CreateProgManGroup (x As Form, GroupName$, GroupPath$)
  350. '-------------------------------------------------------------
  351. ' Procedure: CreateProgManGroup
  352. ' Arguments: X           The Form where a Label1 exist
  353. '            GroupName$  A string that contains the group name
  354. '            GroupPath$  A string that contains the group file
  355. '                        name  ie 'myapp.grp'
  356. '-------------------------------------------------------------
  357.     
  358.     Screen.MousePointer = 11
  359.     
  360.     '----------------------------------------------------------------------
  361.     ' Windows requires DDE in order to create a program group and item.
  362.     ' Here, a Visual Basic label control is used to generate the DDE messages
  363.     '----------------------------------------------------------------------
  364.     On Error Resume Next
  365.  
  366.     
  367.     '--------------------------------
  368.     ' Set LinkTopic to PROGRAM MANAGER
  369.     '--------------------------------
  370.     x.Label1.LinkTopic = "ProgMan|Progman"
  371.     x.Label1.LinkMode = 2
  372.     For i% = 1 To 10                                         ' Loop to ensure that there is enough time to
  373.       z% = DoEvents()                                        ' process DDE Execute.  This is redundant but needed
  374.     Next                                                     ' for debug windows.
  375.     x.Label1.LinkTimeout = 100
  376.  
  377.  
  378.     '---------------------
  379.     ' Create program group
  380.     '---------------------
  381.     x.Label1.LinkExecute "[CreateGroup(" + GroupName$ + Chr$(44) + GroupPath$ + ")]"
  382.  
  383.  
  384.     '-----------------
  385.     ' Reset properties
  386.     '-----------------
  387.     x.Label1.LinkTimeout = 50
  388.     x.Label1.LinkMode = 0
  389.     
  390.     Screen.MousePointer = 0
  391. End Sub
  392.  
  393. [Stop]
  394. [11]
  395. Creates a program manager item
  396. [Code]
  397. Sub CreateProgManItem (x As Form, CmdLine$, IconTitle$)
  398.  
  399. '----------------------------------------------------------
  400. ' Procedure: CreateProgManItem
  401. '
  402. ' Arguments: X           The form where Label1 exists
  403. '
  404. '            CmdLine$    A string that contains the command
  405. '                        line for the item/icon.
  406. '                        ie 'c:\myapp\setup.exe'
  407. '
  408. '            IconTitle$  A string that contains the item's
  409. '                        caption
  410. '----------------------------------------------------------
  411.     
  412.     Screen.MousePointer = 11
  413.     
  414.     '----------------------------------------------------------------------
  415.     ' Windows requires DDE in order to create a program group and item.
  416.     ' Here, a Visual Basic label control is used to generate the DDE messages
  417.     '----------------------------------------------------------------------
  418.     On Error Resume Next
  419.  
  420.  
  421.     '---------------------------------
  422.     ' Set LinkTopic to PROGRAM MANAGER
  423.     '---------------------------------
  424.     x.Label1.LinkTopic = "ProgMan|Progman"
  425.     x.Label1.LinkMode = 2
  426.     For i% = 1 To 10                                         ' Loop to ensure that there is enough time to
  427.       z% = DoEvents()                                        ' process DDE Execute.  This is redundant but needed
  428.     Next                                                     ' for debug windows.
  429.     x.Label1.LinkTimeout = 100
  430.  
  431.     
  432.     '------------------------------------------------
  433.     ' Create Program Item, one of the icons to launch
  434.     ' an application from Program Manager
  435.     '------------------------------------------------
  436.     x.Label1.LinkExecute "[AddItem(" + CmdLine$ + Chr$(44) + IconTitle$ + Chr$(44) + ",,)]"
  437.     
  438.     '-----------------
  439.     ' Reset properties
  440.     '-----------------
  441.     x.Label1.LinkTimeout = 50
  442.     x.Label1.LinkMode = 0
  443.     
  444.     Screen.MousePointer = 0
  445. End Sub
  446.  
  447. [Stop]
  448. [12]
  449. obtain LoWord of Long
  450. [Code]
  451. Function LoWord%(LongVal&)
  452. LOWORD% = LongVal& AND 65535
  453. End Function
  454.  
  455.  
  456. [Stop]
  457. [13]
  458. obtain hiword of long
  459. [Code]
  460. Function HIWORD%(LongVal&)
  461. HIWORD% = LongVal& \ 65536 ' (note: '\', not '/')
  462. End Function
  463. [Stop]
  464. [14]
  465. Function creates confirmation box using specified text, returns True if Yes button pressed, False if No button pressed
  466. [Code]
  467. Function Confirm% (Ask$)
  468. If MsgBox(Ask$, 52, App.Title) = 6 Then Confirm% = True
  469. End Function
  470.  
  471. [Stop]
  472. [15]
  473. Function returns a passed path with backslash at end.
  474. [Code]
  475. Function FixPath$ (Test$)
  476. 'sticks a backslash on the end of test$ if there's
  477. 'not one there already
  478. Dim T$
  479. T$ = Test$
  480. If Right$(T$, 1) <> "\" Then T$ = T$ + "\"
  481. FixPath$ = T$
  482. End Function
  483.  
  484. [Stop]
  485. [16]
  486. Function returns handle of first window matching partial name parameter
  487.  
  488. [Code]
  489. 'Declares for SearchWindowLIst
  490. Declare Function GetWindow% Lib "USER" (ByVal hWnd%, ByVal wCmd%)
  491. Global Const GW_HWNDFIRST = 0
  492. Global Const GW_HWNDNEXT = 2
  493. Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String, ByVal aint As Integer) As Integer
  494.  
  495. Function SearchWindowList% (Cap$)
  496. 'returns handle of first window that matches partial
  497. 'caption passed to function
  498. SearchWindowList% = 0
  499. Dim w%, Y%, winCap As String * 255
  500. w% = GetWindow%(MAKerMain.hWnd, GW_HWNDFIRST)
  501. Do While w% <> 0
  502.    Y% = GetWindowText(w%, winCap, 254)
  503.    If Left$(winCap, Len(Cap$)) = Cap$ Then
  504.       SearchWindowList% = w%
  505.       Exit Do
  506.    End If
  507.    w% = GetWindow%(w%, GW_HWNDNEXT)
  508. Loop
  509. End Function
  510.  
  511.  
  512. [Stop]
  513. [17]
  514. Function removes path from fully-qualified file name, returns file name only.
  515. [Code]
  516. Function StripPath$ (T$)
  517. Dim x%, ct%
  518. StripPath$ = T$
  519. x% = InStr(T$, "\")
  520. Do While x%
  521.    ct% = x%
  522.    x% = InStr(ct% + 1, T$, "\")
  523. Loop
  524. If ct% > 0 Then StripPath$ = Mid$(T$, ct% + 1)
  525. End Function
  526.  
  527. [Stop]
  528. [18]
  529. Trims spaces CHR$(0)'s from string returned by API function.
  530. [Code]
  531. Function FixAPIString$ (ByVal test$)
  532. FixAPIString$ = Trim(Left$(test$, InStr(test$, Chr$(0)) - 1))
  533. End Function
  534.  
  535.  
  536. [Stop]
  537. [19]
  538. Finds and restores a previous running instance of your app
  539. [Code]
  540. Sub FindAndRestorePrevInstance (Cap$)
  541. Dim X%
  542. If App.PrevInstance Then
  543.    AppActivate Cap$
  544.    SendKeys ("% R")
  545.    End
  546. End If
  547. End Sub
  548.  
  549. [Stop]
  550. [20]
  551. This code in Load procedure detects previous instance of program
  552. [Code]
  553. Sub Form_Load () 
  554. If App.PrevInstance Then 
  555.    msg$ = App.EXEName & " already running " 
  556.    MsgBox msg$, 48 
  557.    End 
  558. End If 
  559. End Sub
  560.  
  561.  
  562. [Stop]
  563. [21]
  564. This routine will copy any size and type of file giving a visual progress indication to the user.  Simply pass the Source Filename, Target Filename, and name of the control to use as a progress guage. The code below uses a standard Panel3D1 control from THREED.VBX but any control that gives the desired effect may be used. The progress range is 1 to 100 but can be any range.
  565. [Code]
  566. Sub VisualFileCopy (SourceFileName As String, TargetFileName As String, 
  567. ProgressGuage As Control)
  568.  
  569.    Dim I As Integer
  570.    Dim SourceFileNo As Integer
  571.    Dim TargetFileNo As Integer
  572.    Dim SourceFileSize As Long
  573.    Dim CopyBuffer As String
  574.    
  575.    On Error GoTo FileCopyErrorRoutine
  576.    SourceFileSize = FileLen(SourceFileName)
  577.    CopyBuffer = Space$(25000)             'AS LARGE AS POSSIBLE UNDER 65,000
  578.    
  579. '--KILL THE CURRENT TARGET FILE IF IT EXISTS
  580.    If Len(Dir$(TargetFileName)) Then
  581.       Kill TargetFileName
  582.    End If
  583.  
  584. '--OPEN FILES
  585.    SourceFileNo = FreeFile
  586.    Open SourceFileName For Binary Access Read As SourceFileNo
  587.    TargetFileNo = FreeFile
  588.    Open TargetFileName For Binary Access Write As TargetFileNo
  589.  
  590. '--COPY SOURCE FILE TO TARGET FILE
  591.    For I = 1 To SourceFileSize \ Len(CopyBuffer)
  592.       Get #SourceFileNo, , CopyBuffer
  593.       ProgressGuage.FloodPercent = I * Len(CopyBuffer) / SourceFileSize * 100  
  594. 'UPDATE PROGRESS GUAGE
  595.       Put #TargetFileNo, , CopyBuffer
  596.       DoEvents
  597.    Next I
  598.  
  599. '--COPY ANY ODD PORTION OF THE SOURCE FILE REMAINING
  600.    CopyBuffer = Space$(SourceFileSize - Loc(TargetFileNo))
  601.    If Len(CopyBuffer) Then
  602.       Get #SourceFileNo, , CopyBuffer
  603.       Put #TargetFileNo, , CopyBuffer
  604.    End If
  605.    Close SourceFileNo
  606.    Close TargetFileNo
  607.  
  608. Exit Sub
  609.  
  610. FileCopyErrorRoutine:
  611.    MsgBox Error$
  612.    Exit Sub
  613. End Sub
  614.  
  615.  
  616.  
  617.  
  618.  
  619. [Stop]
  620. [22]
  621.  
  622. [Code]
  623.  
  624. Sub waitforeventstofinish (NbrTimes As Integer)
  625.    
  626.    Dim dummy As Integer
  627.  
  628.     Dim i As Integer
  629.  
  630.     For i = 1 To NbrTimes
  631.         dummy% = DoEvents()
  632.     Next i
  633.  
  634. End Sub
  635.  
  636.  
  637. [Stop]
  638. [23]
  639. Use this code with the Startup form procedure. Use CenterMe for non-MDI windows such as a dialog box. You should use CenterMe BEFORE you use Show to display the form. For two reasons: 
  640. 1.) If you use CenterMe after Show, you will see the form move at run-time. This looks very unprofessional.
  641. 2.) If you display the form as modal (form.Show 1) and then use CenterMe, Visual Basic won't listen to the next command following Show until your new form is removed from the screen. You can use CenterMe in the Form_Load event, causing the form to be centered each time it's loaded, or before the Show method.
  642.  
  643. You can use CenterMe in the Form_Resize event. This will make the window always centered, even if the user changes the size of your form.
  644.  
  645.  
  646. [Code]
  647.  
  648.     Sub CenterMe (frm as Form)
  649.         Dim x, y        'New directions for the form
  650.         
  651.         x = (Screen.Width - frm.Width) / 2
  652.         y = (Screen.Height - frm.Height) / 2
  653.         frm.Move x, y        'Change the location of the form
  654.     End Sub
  655.  
  656.  
  657.  
  658. [Stop]
  659. [24]
  660. This routine will move a menu caption to the far right of a menu. (Usually this is the Help caption.)
  661. [Code]
  662.  
  663. Form_Load event.
  664. Menu.Caption= Chr$(8) & Menu.Caption
  665. 'Replace Menu with a real control menu name such as menuHelp.
  666.  
  667.  
  668.  
  669. [Stop]
  670. [25]
  671. Discarding Letters:  The following code only accepts the digits zero through nine.
  672. [Code]
  673.  
  674. Sub Text1_KeyPress (KeyAscii As Integer)
  675.     If KeyAscii < Asc (" ") Then        'Is this Control Char
  676.         Exit Sub
  677.     End If
  678.  
  679.     If KeyAscii < Asc ("0") Or KeyAscii > Asc ("9") Then
  680.         KeyAscii = 0
  681.     End If
  682. End Sub
  683.  
  684. [Stop]
  685. [26]
  686. This subroutine (DoKeyPress) discards any characters that can't be in a number format. The only characters allowed are:
  687.     0 - 9 All digits
  688.     -        A minus, only if it is the first character
  689.     .       Periods are allowed
  690.  
  691.  
  692. [Code]
  693.  
  694. 'Type this code in a module or the declarations of a form.
  695. 'There is also another subroutine DoKeyPress uses, CheckPeriod.
  696.  
  697. Sub DoKeyPress (t As Control, KeyAscii As Integer)
  698.     If KeyAscii < Asc(" ") Then     ' Is this Control char?
  699.         Exit Sub                    ' Yes, let it pass
  700.     End If
  701.  
  702.     CheckPeriod t                   ' Remove excess periods
  703.  
  704.     If KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Then
  705.         ' keep digit
  706.     ElseIf KeyAscii = Asc(".") Then
  707.         ' keep .
  708.     ElseIf KeyAscii = Asc("-") And t.SelStart = 0 Then
  709.         ' Keep - only if first char
  710.     Else
  711.         KeyAscii = 0                ' Discard all other chars
  712.     End If
  713.  
  714.   
  715.     ' This code keeps you from typing any characters in front of
  716.     ' a minus sign.
  717.     
  718.     If Mid$(t.Text, t.SelStart + t.SelLength + 1, 1) = "-" Then
  719.         KeyAscii = 0                ' Discard chars before -
  720.     End If
  721. End Sub
  722.  
  723.  
  724.  
  725. [Stop]
  726. [27]
  727. Use this with the DoKeyPress subroutine. The subroutine, DoKeyPress needs the procedure. This subroutine makes sure a text box never has more than one period in it. You can also use this subroutine separate with your project.
  728. [Code]
  729.  
  730. Sub CheckPeriod (t As Control)
  731.  
  732.     Dim i As Integer
  733.     
  734.     i = InStr(1, t.Text, ".")   ' Look for a period
  735.     If i > 0 And InStr(i + 1, t.Text, ".") > 0 Then
  736.         t.SelStart = t.SelStart - 1
  737.         t.SelLength = 1         ' Select new period
  738.         t.SelText = ""          ' Remove new period
  739.     End If
  740. End Sub
  741.  
  742.  
  743.  
  744.  
  745. [Stop]
  746. [28]
  747. The Visual Basic textbox control does not support Overtype mode. Add this code to a textbox to enable the Insert key.
  748. [Code]
  749.  
  750. Sub Text1_KeyPress (KeyAscii As Integer)
  751.     If KeyAscii <> 8 And KeyAscii <> 13 And Text1.SelLength = 0 Then
  752.         Text1.SelLength = 1
  753.     End If
  754. End Sub
  755.  
  756.  
  757. [Stop]
  758. [29]
  759. How to format a floppy disk from Visual Basic.
  760.  
  761. [Code]
  762. 'Declares for Format a Floppy Disk
  763.  
  764. Type Rect
  765.     Left As Integer
  766.     Top As Integer
  767.     Right As Integer
  768.     Bottom As Integer
  769. End Type
  770.  
  771. Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) 
  772. Declare Sub GetWindowRect Lib "User" (ByVal hWnd As Integer, lpRect As Rect)
  773. Declare Function IsWindow Lib "User" (ByVal hWnd As Integer) As Integer
  774. Declare Function WinExec Lib "Kernel" (ByVal lpCmdLine As String, ByVal nCmdShow As Integer) As Integer 
  775. Declare Function SetActiveWindow Lib "User" (ByVal hWnd As Integer) As Integer Declare Function GetActiveWindow Lib "User" () As Integer 
  776. Declare Function LockWindowUpdate Lib "User" (ByVal hwndLock As Integer) As Integer
  777. Declare Function GetDesktopWindow Lib "User" () As Integer 
  778. Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer 
  779. Declare Function PostMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Integer 
  780. Const WM_COMMAND = &H111
  781. Const WM_CLOSE = &H10 
  782. Dim wFlag% 
  783. Dim lpDlgRect As Rect 
  784. Dim lpDskRect As Rect 
  785. Const SWP_NOSIZE = &H1 
  786. Const SWP_NOZORDER = &H4
  787.  
  788.  
  789.  
  790. Sub CenterDialog (WinText As String)
  791.    Do
  792.     If FindWindow(0&, WinText) Then Exit Do
  793.     x% = DoEvents()
  794.    Loop
  795.  
  796.  wnd% = GetActiveWindow()
  797.  Call GetWindowRect(wnd%, lpDlgRect)
  798.  wdth% = lpDlgRect.Right - lpDlgRect.Left
  799.  hght% = lpDlgRect.Bottom - lpDlgRect.Top
  800.  Call GetWindowRect(GetDesktopWindow(), lpDskRect)
  801.  Scrwdth% = lpDskRect.Right - lpDskRect.Left
  802.  Scrhght% = lpDskRect.Bottom - lpDskRect.Top
  803.  x% = (Scrwdth% - wdth%) / 2
  804.  Y% = (Scrhght% - hght%) / 2
  805.  Call SetWindowPos(wnd%, 0, x%, Y%, 0, 0, SWP_NOZORDER Or SWP_NOSIZE) 
  806. End Sub
  807.  
  808. Sub FMFormat (F As Form)
  809.  
  810.     FMhWnd = FindWindow("WFS_Frame", 0&)
  811.  
  812.     If FMhWnd = 0 Then
  813.     i% = WinExec("Winfile", 0)
  814.     FMhWnd = FindWindow("WFS_Frame", 0&)
  815.        If FMhWnd = 0 Then
  816.            MsgBox "FileMan ain't home"
  817.            Exit Sub
  818.        End If
  819.     wFlag = 1
  820.     End If
  821.  
  822.     i% = LockWindowUpdate(GetDesktopWindow())
  823.  
  824.     i% = PostMessage(FMhWnd, WM_COMMAND, &HCB, 0)
  825.  
  826.     Call CenterDialog("Format Disk")
  827.  
  828.     i% = LockWindowUpdate(0)
  829.  
  830.     wnd% = GetActiveWindow()
  831.  
  832.     While IsWindow(wnd%)
  833.     x = DoEvents()
  834.     Wend
  835.  
  836.     x = DoEvents()
  837.  
  838.     If wFlag Then
  839.     wFlag = 0
  840.     i% = PostMessage(FMhWnd, WM_CLOSE, 0, 0)
  841.     End If
  842.  
  843.     i% = SetActiveWindow(F.hWnd)
  844.  
  845. End Sub
  846.  
  847.  
  848.  
  849.  
  850. [Stop]
  851. [30]
  852. This routine allows you the dynamically remove the title bar from a VB form.
  853.  
  854.  
  855. [Code]
  856. 'Declares for Remove Title Bar
  857.  
  858. DefInt A-Z
  859. Option Explicit
  860.  
  861. Declare Function GetWindowWord% Lib "User" (ByVal hWnd%, ByVal nIndex%)
  862. Declare Function SetWindowWord% Lib "User" (ByVal hWnd%, ByVal nIndex%, 
  863. ByVal w
  864. NewWord%)
  865. Declare Function GetWindowLong& Lib "User" (ByVal hWnd%, ByVal nIndex%)
  866. Declare Function SetWindowLong& Lib "User" (ByVal hWnd%, ByVal nIndex%, ByVal 
  867. d
  868. wNewLong&)
  869.  
  870. Const GWW_ID = (-12)
  871. Const GWL_STYLE = (-16)
  872.  
  873. Const WS_DLGFRAME = &H400000
  874. Const WS_SYSMENU = &H80000
  875. Const WS_MINIMIZEBOX = &H20000
  876. Const WS_MAXIMIZEBOX = &H10000
  877.  
  878.  
  879. Sub TitleBar (frm As Form, ShowTitle)
  880.    Static Oldhmenu, SavedStyle&
  881.  
  882.    Dim NewStyle&, t&
  883.  
  884.    If ShowTitle Then
  885.       'get the current style attributes
  886.       NewStyle& = GetWindowLong&(frm.hWnd, GWL_STYLE)
  887.       
  888.       'set only the attributes that were removed earlier
  889.       NewStyle& = NewStyle& Or SavedStyle&
  890.       
  891.       're-establish the menu
  892.       If Oldhmenu <> 0 Then
  893.          t& = SetWindowWord%(frm.hWnd, GWW_ID, Oldhmenu)
  894.       End If
  895.       
  896.       'set the new style
  897.       t& = SetWindowLong&(frm.hWnd, GWL_STYLE, NewStyle&)
  898.       
  899.       'force VB to update the form
  900.       frm.Left = frm.Left
  901.       frm.Refresh
  902.    Else
  903.       'get the current style attributes
  904.       NewStyle& = GetWindowLong&(frm.hWnd, GWL_STYLE)
  905.  
  906.       'determine whether the form has a dialog frame, a ControlBox,
  907.       'a minimize button, or a maximize button and save this info.
  908.       'for later use
  909.       SavedStyle& = 0
  910.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_DLGFRAME)
  911.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_SYSMENU)
  912.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_MINIMIZEBOX)
  913.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_MAXIMIZEBOX)
  914.  
  915.       'remove the attributes for a dialog frame, a ControlBox, a minimize
  916.       'button and a maximize button
  917.       NewStyle& = NewStyle& And Not WS_DLGFRAME
  918.       NewStyle& = NewStyle& And Not WS_SYSMENU
  919.       NewStyle& = NewStyle& And Not WS_MINIMIZEBOX
  920.       NewStyle& = NewStyle& And Not WS_MAXIMIZEBOX
  921.  
  922.       'is there a menu associated with this form?
  923.       Oldhmenu = GetWindowWord%(frm.hWnd, GWW_ID)
  924.       If Oldhmenu <> 0 Then
  925.          'yes-zero it the menu handle
  926.          t& = SetWindowWord%(frm.hWnd, GWW_ID, 0)
  927.       End If
  928.    
  929.       'set the new style
  930.       t& = SetWindowLong&(frm.hWnd, GWL_STYLE, NewStyle&)
  931.  
  932.       'force VB to update the form and get rid of the title bar
  933.       frm.Left = frm.Left
  934.       frm.Refresh
  935.    End If
  936. End Sub
  937.  
  938. ' Syntax:
  939. '    TitleBar Form1, False        This will remove the title bar
  940. '    TitleBar Form1, True         This will restore the title bar
  941.  
  942. Sub TitleBar (frm As Form, ShowTitle)
  943.    Static Oldhmenu, SavedStyle&
  944.  
  945.    Dim NewStyle&, t&
  946.  
  947.    If ShowTitle Then
  948.       'get the current style attributes
  949.       NewStyle& = GetWindowLong&(frm.hWnd, GWL_STYLE)
  950.       
  951.       'set only the attributes that were removed earlier
  952.       NewStyle& = NewStyle& Or SavedStyle&
  953.       
  954.       're-establish the menu
  955.       If Oldhmenu <> 0 Then
  956.          t& = SetWindowWord%(frm.hWnd, GWW_ID, Oldhmenu)
  957.       End If
  958.       
  959.       'set the new style
  960.       t& = SetWindowLong&(frm.hWnd, GWL_STYLE, NewStyle&)
  961.       
  962.       'force VB to update the form
  963.       frm.Left = frm.Left
  964.       frm.Refresh
  965.    Else
  966.       'get the current style attributes
  967.       NewStyle& = GetWindowLong&(frm.hWnd, GWL_STYLE)
  968.  
  969.       'determine whether the form has a dialog frame, a ControlBox,
  970.       'a minimize button, or a maximize button and save this info.
  971.       'for later use
  972.       SavedStyle& = 0
  973.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_DLGFRAME)
  974.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_SYSMENU)
  975.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_MINIMIZEBOX)
  976.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_MAXIMIZEBOX)
  977.  
  978.       'remove the attributes for a dialog frame, a ControlBox, a minimize
  979.       'button and a maximize button
  980.       NewStyle& = NewStyle& And Not WS_DLGFRAME
  981.       NewStyle& = NewStyle& And Not WS_SYSMENU
  982.       NewStyle& = NewStyle& And Not WS_MINIMIZEBOX
  983.       NewStyle& = NewStyle& And Not WS_MAXIMIZEBOX
  984.  
  985.       'is there a menu associated with this form?
  986.       Oldhmenu = GetWindowWord%(frm.hWnd, GWW_ID)
  987.       If Oldhmenu <> 0 Then
  988.          'yes-zero it the menu handle
  989.          t& = SetWindowWord%(frm.hWnd, GWW_ID, 0)
  990.       End If
  991.    
  992.       'set the new style
  993.       t& = SetWindowLong&(frm.hWnd, GWL_STYLE, NewStyle&)
  994.  
  995.       'force VB to update the form and get rid of the title bar
  996.       frm.Left = frm.Left
  997.       frm.Refresh
  998.    End If
  999. End Sub
  1000.  
  1001.  
  1002. [Stop]
  1003. [31]
  1004. Convert characters to uppercase/lowercase in an edit box.
  1005. [Code]
  1006.  
  1007. 'for simple combo box, - no drop down
  1008.    Dim hwndListbox As Integer
  1009.    Dim childhWnd As Integer
  1010.  
  1011.    hwndListbox = GetWindow(cbo1.hWnd, GW_CHILD)
  1012.    childhWnd = GetWindow(hwndListbox, GW_HWNDNEXT)
  1013.  
  1014.    lStyle = GetWindowLong(childhWnd, GWL_STYLE)
  1015.    lStyle = lStyle Or ES_UPPERCASE
  1016.    lRes = SetWindowLong(childhWnd, GWL_STYLE, lStyle)
  1017.  
  1018. 'for drop down combo
  1019.    childhWnd = GetWindow(cbo1.hWnd, gw_child)
  1020.  
  1021.    lStyle = GetWindowLong(childhWnd, GWL_STYLE)
  1022.    lStyle = lStyle Or ES_UPPERCASE
  1023.    lRes = SetWindowLong(childhWnd, GWL_STYLE, lStyle)
  1024.  
  1025. 'plain old simple text box
  1026.    lStyle = GetWindowLong(Txt1.hWnd, GWL_STYLE)
  1027.    lStyle = lStyle Or ES_UPPERCASE
  1028.    lRes = SetWindowLong(Txt1.hWnd, GWL_STYLE, lStyle)
  1029.  
  1030. [Stop]
  1031. [32]
  1032. How to make a textbox read only and how to prevent  the user from changing the text. 
  1033. [Code]
  1034. 'Declares for Read Only Text Box
  1035.  
  1036. Global Const WM_USER = &H400
  1037. Global Const EM_SETREADONLY = (WM_USER + 31)
  1038.  
  1039. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  1040.  
  1041.  
  1042.  
  1043.  
  1044. SendMessage(Text1.hWnd, EM_SETREADONLY, 1, 0)
  1045. [Stop]
  1046. [33]
  1047. To create a tool box for an application, simply set up a form as a parent and another form as a the toolbox/floating dialog whatever.  If you try tbox.show 1 i.e. modal you'll find the form will show but you will be unable to do anything with it. Secondly you absolutely *MUST* unload the child form i.e. 
  1048. tbox BEFORE unloading the main form otherwise your program will crash.
  1049.  
  1050. [Code]
  1051. 'Declares for Tool Box
  1052.  
  1053. 'In a suitable declarations section declare the API function as follows:
  1054.  
  1055. Declare Function SetParent% Lib "User" (ByVal hWndChild%, ByVal hWndNewParent%)
  1056.  
  1057.  
  1058.  
  1059.  
  1060. Sub ShowTbox_Click () 
  1061. Dim ret As Integer 
  1062. If doshow = False Then 'toolbox not visible 
  1063.    ret = SetParent(tbox.hWnd, parent.hWnd) 'this makes the toolbox float 
  1064.    tbox.Left = 0 'sets position to top left corner of parent 
  1065.    tbox.Top = 0 
  1066.    tbox.Show 'makes toolbox visible 
  1067.    'try tbox.show 1 i.e. modal to see what happens 
  1068.    doshow = True 
  1069.    Showtbox.Caption = "&Hide Toolbox" 
  1070.       Else 
  1071.          tbox.Hide 
  1072.      doshow = False 
  1073.      Showtbox.Caption = "&Show Toolbox" 
  1074. End If 
  1075. End Sub
  1076.  
  1077. [Stop]
  1078. [34]
  1079. Listed below is a subroutine that will quit windows in three different ways if needed.  Passing 1 to it will reboot the computer, passing 2 will restart Windows, and passing 3 will exit Windows and return to DOS.
  1080.  
  1081. [Code]
  1082. 'Declares for Restart/Exit Windows
  1083.  
  1084. Declare Function ExitWindows Lib "User" (ByVal RestartCode As Long,ByVal 
  1085. DOSReturnCode As Integer) As Integer
  1086.  
  1087.  
  1088.  
  1089.  
  1090. 'Add this subroutine to a module:
  1091.  
  1092. Sub ExitWin (ByVal nExitOption As Integer) Dim n As Integer
  1093.  
  1094. n = MsgBox("Do you really want to exit Windows?", 36, "Exiting")
  1095.  
  1096.     If n = 7 Then Exit Sub 'User chose NO
  1097.  
  1098.     Select Case nExitOption
  1099.         Case 1
  1100.             n = ExitWindows(67, 0) 'reboot the computer
  1101.         Case 2
  1102.             n = ExitWindows(66, 0) 'restart Windows
  1103.         Case 3
  1104.             n = ExitWindows(0, 0) 'exit Windows
  1105.     End Select
  1106.  
  1107. End Sub
  1108.  
  1109. [Stop]
  1110. [35]
  1111. How do you write a code that checks if the user chose Yes instead of No in a msgbox? Or Yes instead of Cancel?
  1112. [Code]
  1113. Dim Msg
  1114. Msg = "Pick Yes or No"            'Here's a message
  1115. If MsgBox(Msg$, 4 + 32 + 256) <> 6 Then      'Msgbox with a question mark                
  1116.                 'andYES/ NO buttons.
  1117.     Msgbox "You chose No"
  1118. Else
  1119.     Msgbox "You chose Yes"
  1120. End If
  1121.  
  1122.  
  1123. 'This is what it means:
  1124. 'IF MsgBox(Msg.....) <> 6 Then
  1125. 'If the user chose anything besides Yes (Yes means 6) then
  1126. '.... do whatever needs to be done.
  1127. 'End If
  1128.  
  1129.  
  1130.  
  1131.  
  1132. [Stop]
  1133. [36]
  1134. Set the Timer's Interval to 60,000 put the following into the Timer_Timer event. This code will trigger code in 5 minutes. Great for an auto save routine!
  1135.  
  1136.  
  1137. [Code]
  1138. Static Counter As Integer
  1139.   Counter% = Counter% + 1
  1140.   
  1141.   If Counter% = 5 Then      
  1142.      Counter% = 0        'insert this line if you want the counter to reset
  1143. itself when it reaches 5 mins
  1144.      [YOUR CODE GOES HERE]
  1145.   End If
  1146.  
  1147.  
  1148.  
  1149. [Stop]
  1150. [37]
  1151. How to make a backgorund of a form have a gradiated style of backgorund.
  1152.  
  1153. Special thanks to:  JwpcEMail@aol.com
  1154. [Code]
  1155. 'Declares for Gradient Background Color
  1156. Type RECT
  1157.     Left As Integer
  1158.     Top As Integer
  1159.     Right As Integer
  1160.     Bottom As Integer
  1161. End Type
  1162.  
  1163. '  API Functions used to create solid brush and draw brush on form
  1164. Declare Function CreateSolidBrush Lib "GDI" (ByVal crColor As Long) As Integer
  1165. Declare Function FillRect Lib "User" (ByVal hDC As Integer, lpRect As RECT, ByVal hBrush As Integer) As Integer
  1166. Declare Function DeleteObject Lib "GDI" (ByVal hObject As Integer) As Integer
  1167.  
  1168. Dim hBrush%
  1169.  
  1170.  
  1171.  
  1172. 'Place the follwing two routines into the main form
  1173.  
  1174. Sub Form_Paint ()
  1175. fadeform Me
  1176. End Sub
  1177.  
  1178. Sub Form_Resize ()
  1179. fadeform Me
  1180. End Sub
  1181.  
  1182. 'Place the following code in a the general declarations of
  1183. 'a .bas file called: Fade.bas
  1184.  
  1185. Sub fadeform (TheForm As Form)
  1186.     Dim FormHeight%, red%, StepInterval%, X%, RetVal%, OldMode%
  1187.     Dim FillArea As RECT
  1188.     OldMode = TheForm.ScaleMode
  1189.     TheForm.ScaleMode = 3  'Pixel
  1190.     FormHeight = TheForm.ScaleHeight
  1191. ' Divide the form into 63 regions
  1192.     StepInterval = FormHeight \ 63
  1193.     red = 255
  1194.     FillArea.Left = 0
  1195.     FillArea.Right = TheForm.ScaleWidth
  1196.     FillArea.Top = 0
  1197.     FillArea.Bottom = StepInterval
  1198.     For X = 1 To 63
  1199.         hBrush% = CreateSolidBrush(RGB(0, 0, red))
  1200.         RetVal% = FillRect(TheForm.hDC, FillArea, hBrush)
  1201.         RetVal% = DeleteObject(hBrush)
  1202.         red = red - 4
  1203.         FillArea.Top = FillArea.Bottom
  1204.         FillArea.Bottom = FillArea.Bottom + StepInterval
  1205.     Next
  1206. ' Fill the remainder of the form with black
  1207.     FillArea.Bottom = FillArea.Bottom + 63
  1208.     hBrush% = CreateSolidBrush(RGB(0, 0, 0))
  1209.     RetVal% = FillRect(TheForm.hDC, FillArea, hBrush)
  1210.     RetVal% = DeleteObject(hBrush)
  1211.     TheForm.ScaleMode = OldMode
  1212. End Sub
  1213.  
  1214.  
  1215.  
  1216.  
  1217. [Stop]
  1218.